<template>
	<view class="container">
		<header-swiper :list="pageMessage"></header-swiper>
		<mescroll-body @init="mescrollInit" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback">
			<view class="common-list">
				<block v-for="(item, index) in pageGeneral" :key="index"><yxyl-common :type="item.itemStyle" :rowData="item.items"></yxyl-common></block>
			</view>
			<mescroll-empty v-if="pageGeneral.length==0"></mescroll-empty>
		</mescroll-body>
	</view>
</template>

<script>
import headerSwiper from '@/components/headerSwiper/headerSwiper.vue';
import yxylCommon from '@/components/yxyl-common/yxyl-common.vue';
import MescrollBody from 'mescroll-uni/mescroll-body.vue'
import MescrollMixin from "mescroll-uni/mescroll-mixins.js";
import MescrollEmpty from 'mescroll-uni/components/mescroll-empty.vue';
export default {
	mixins: [MescrollMixin],
	components: { headerSwiper, yxylCommon, MescrollBody, MescrollEmpty },
	data() {
		return {
			id: '',
			filter: '',
			contentType: 1,
			pageMessage: [],
			pageGeneral: [],
			downOption: {
				use: true, // 是否启用下拉刷新; 默认true,
				auto: false,
				native:true
			},
			//上拉加载的常用配置
			upOption: {
				use: true, // 是否启用上拉加载; 默认true
				auto: false, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true

				noMoreSize: 2, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				empty: false,
				textNoMore: '---没有了---'
			}
		};
	},
	onLoad(e) {
		this.id = e.Id || '';
		this.filter = e.Filter || '';
		this.contentType = e.ContentType || 1;
		this.bindpageGeneral().then(() => {
			// #ifdef H5
			this.$wechat.share({
				link: this.$handlerAppMessagePath()
			});
			// #endif
		});
	},
	methods: {
		onShareAppMessage(e) {
			return {
				path: this.$handlerAppMessagePath()
			};
		},
		async downCallback() {
			try {
				this.pageGeneral = [];
				await this.bindpageGeneral();
				this.mescroll.endSuccess();
			} catch (e) {
				this.mescroll.endErr();
			}
		},
		async upCallback(page) {
			try {
				var Count = await this.bindpageGeneral();
				this.mescroll.endSuccess(Count, Count > 0);
			} catch (e) {
				// 失败隐藏下拉加载状态
				this.mescroll.endErr();
			}
		},
		async bindpageGeneral() {
			var result = await this.$http.request({
				url: 'api/CommonPage/GetCmsAll2',
				data: {
					id: this.id || '',
					filter: this.filter || '',
					contentType: this.contentType || '',
					SkipCount: this.pageGeneral.length,
					MaxResultCount: 30
				}
			});
			if(result.pageMessage){
				this.pageMessage = result.pageMessage;
			}
			uni.setNavigationBarTitle({
				title: result.pageTitle
			})
			this.pageGeneral = this.pageGeneral.concat(result.data);
			return result.data.length;
		}
	}
};
</script>

<style lang="scss" scoped>
.common-list {
	width: 95%;
	margin: 0 auto;
}
</style>
